/**
 * 
 */
package com.googlecode.pcapj;



/**
 * 
 */
class MACAddressImpl implements MACAddress{
	private BinaryData binaryData;
	/**
	 * @param buffer
	 * @param offset
	 */
	MACAddressImpl(byte[] buffer, int offset) {
		super();
		binaryData = new BinaryData(buffer, offset, 6);
	}

	/* (non-Javadoc)
	 * @see com.googlecode.pcapj.MACAddress#getBytes()
	 */
	public byte[] getBytes() {
		return binaryData.getBytes();
	}

	/* (non-Javadoc)
	 * @see com.googlecode.pcapj.MACAddress#getString()
	 */
	public String getString() {
		StringBuffer stringBuffer = new StringBuffer(17);
		for (int i = 0; i < 6; i++) {
			if(i != 0){
				stringBuffer.append(":");	
			}
			int n = 0xff & binaryData.getByte(i);
			if(n < 0x10){
				stringBuffer.append("0");
			}
			stringBuffer.append(Integer.toHexString(n));
		}
		return stringBuffer.toString();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return getString();
	}
}
